home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Tools&Utilities / Plotfoil 3.2 / mixfoils.c < prev    next >
C/C++ Source or Header  |  1994-12-12  |  4KB  |  159 lines

  1.  
  2. /*
  3.  * mixfoils.c - read in two airfoils and generate an intermediate one
  4.  *
  5.  * (I don't know how useful this is... maybe there needs to be a way of
  6.  * adding twist too, maybe I want a wing with 7032 at the root, 7037 at the
  7.  * tips, uniform 3 deg. washout, and I want the section at the poly break
  8.  * at 70% span. Maybe some other time.)
  9.  *
  10.  * Copyright 1994 Shamim P. Mohamed
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; if not, write to the Free Software
  24.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  *
  26.  * Author:
  27.  * shamim@math.isu.edu
  28.  * Shamim Mohamed
  29.  * Dept. of Mathematics
  30.  * Idaho State University
  31.  *
  32.  */
  33.  
  34. #include "mixfoils.h"
  35.  
  36. static char copyright[] = "\
  37. Mixfoil v1.0, Copyright 1994 Shamim Mohamed. This is free software\n\
  38. and is freely distributable under certain conditions; it comes with\n\
  39. NO WARRNATY. See the file \"COPYING\" for details.\n";
  40.  
  41. static char usage_str[] = "\n\
  42. Usage: %s [-hq] [-o output-file] [-r ratio] section1 section2 \n\
  43. \n\
  44. Options:\n\
  45.    -q : Don't print the copyright message\n\
  46.    -h : Print this help\n\
  47. These take arguments:\n\
  48.    -r : ratio, between 0 and 100 (default is 50)\n\
  49. (Under MS-DOS, / can be used for options instead of -.)\n";
  50.  
  51. static void merge(airfoil_data_t *new,
  52.           airfoil_data_t *foil1, airfoil_data_t *foil2, float ratio);
  53.  
  54. int main(int argc, char *argv[])
  55. {
  56.    int qflag=0;
  57.    FILE *fp, *fout=stdout;
  58.    int argp = 1;
  59.    airfoil_data_t foil1, foil2, newfoil;
  60.    char *fname, *p;
  61.    float ratio = 50.;
  62.    
  63.    while(argc > argp) {
  64.       p = argv[argp];
  65.       if(optionchar(*p) && (*(p+1) != 0)) {
  66.          switch (*(p+1)) {
  67.      case 'r':
  68.             if(sscanf(p = argv[++argp], "%f", &ratio) != 1 ||
  69.            ratio < 0. || ratio > 100.) {
  70.                fprintf(stderr, "Invalid argument for -r: \"%s\"\n", p);
  71.                break;
  72.             }
  73.      case 'q':
  74.         qflag++; break;
  75.      case 'o':
  76.             fname = argv[++argp];
  77.             if((fout = fopen(fname, "w")) == NULL) {
  78.                fprintf(stderr, "Could not open \"%s\" for writing!\n", fname);
  79.                fout = stdout;
  80.             }
  81.             break;
  82.  
  83.          case '-':
  84.             goto done_opts;
  85.          case 'h':
  86.          case '?':
  87.          default:
  88.             fprintf(stderr, usage_str, argv[0], argv[0]);
  89.             exit(1);
  90.          }
  91.       }
  92.       else
  93.          break;
  94.       argp++;
  95.    }
  96.  
  97.  done_opts:
  98.  
  99.    if(!qflag)
  100.       fputs(copyright, stderr);
  101.  
  102.    if((argc - argp) != 2) {
  103.       fprintf(stderr, "%s: %d need two filenames to merge!\n", argv[0], argp);
  104.       exit(1);
  105.    }
  106.  
  107.    if((fp = fopen((fname = argv[argp++]), "r")) == NULL) {
  108.       fprintf(stderr, "%s: can't open \"%s\"\n", argv[0], fname);
  109.       exit(1);
  110.    }
  111.    if(!read_foil(fp, fname, &foil1))
  112.       exit(1);
  113.  
  114.    if((fp = fopen((fname = argv[argp++]), "r")) == NULL) {
  115.       fprintf(stderr, "%s: can't open \"%s\"\n", argv[0], fname);
  116.       exit(1);
  117.    }
  118.    if(!read_foil(fp, fname, &foil2))
  119.       exit(1);
  120.  
  121.    ratio /= 100.0;
  122.    merge(&newfoil, &foil1, &foil2, ratio);
  123.    writefoil(fout, &newfoil, 0, 0);
  124.    
  125.    exit(0);
  126.  
  127.    /* well... */
  128.    return 0;
  129. }
  130.  
  131. static void merge(airfoil_data_t *new,
  132.           airfoil_data_t *foil1, airfoil_data_t *foil2, float ratio)
  133. {
  134.    airfoil_data_t *temp;
  135.    point_t foil2normalised[MAXPOINTS];
  136.    int i;
  137.  
  138.    if(foil1->npoints < foil2->npoints) {
  139.       temp = foil1; foil1 = foil2; foil2 = temp;
  140.       ratio = 1.0 - ratio;
  141.    }
  142.    
  143.    new->npoints = foil1->npoints;
  144.    sprintf(new->title, "%s (%.3g%%), %s (%.3g%%)", foil1->title, ratio*100,
  145.        foil2->title, (1.0-ratio)*100);
  146.  
  147.    for(i = 0; i < foil1->npoints; i++)
  148.       foil2normalised[i].x = foil1->points[i].x;
  149.  
  150.    fill_in(foil2normalised, foil1->npoints, foil2->points, foil2->npoints);
  151.  
  152.    for(i = 0; i < foil1->npoints; i++) {
  153.       new->points[i].x = foil1->points[i].x;
  154.       new->points[i].y = ratio * foil2normalised[i].y +
  155.      (1.0 - ratio) * foil1->points[i].y;
  156.    }
  157. }
  158.  
  159.